from enum import Enum
from core.database import db_manager
from dao.config_dao import ConfigDao

class ConfigKey(Enum):
    WORKSPACE_PATH = "future_backtest.workspace_path"

class ConfigService:
    def __init__(self):
        self.db = db_manager
        self.config_dao = ConfigDao(self.db)

    def get(self, key: ConfigKey, default=None):
        """
        Retrieves a value by its key.
        """
        result = self.config_dao.get(key.value)
        if result:
            return result.get('value', default)
        return default

    def set(self, key: ConfigKey, value, desc=None):
        """
        Inserts or updates a key-value pair.
        """
        self.config_dao.set(key.value, value, desc)

    def delete(self, key):
        """
        Deletes a key-value pair.
        """
        self.config_dao.delete(key)
